package meta

import "strings"

type CollectorMeta struct {
	//分组列列表
	fields []string
	//索引的名字
	name string
	//查询键，但不适用于golang
	accessorKey string
}

func NewCollectorMeta(fields []string) *CollectorMeta {
	var meta CollectorMeta
	meta.fields = fields
	meta.buildName()
	meta.buildAccessorKey()
	return &meta
}

func (meta *CollectorMeta) buildName() {
	var name string
	for i, v := range meta.fields {
		if i == 0 {
			name += v
		} else {
			name += strings.ToUpper(v[0:1]) + v[1:]
		}
	}
	meta.name = name + "Collector"
}

func (meta *CollectorMeta) buildAccessorKey() {
	//TODO 对于golang，数字不能直接与字符串进行拼接
	var key string
	for i, v := range meta.fields {
		if i == 0 {
			key += "\"\" + " + v
		} else {
			key += "+ \"_\" + " + v
		}
	}
	meta.accessorKey = key
}
